﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.BLL.LM;
using SHKF.B2C.Model.Dto;
using SHKF.B2C.Model.Dto.ReturnOrder;
using SHKF.B2C.Model.Entity.LM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SHKF.B2C.Service.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class ReturnOrderController : Base2Controller
    {
        private readonly RetrunOrderBLL retrunOrderBLL;

        public ReturnOrderController(
              RetrunOrderBLL retrunOrderBLL,
              IServiceProvider serviceProvider,
            ILogger<ReturnOrderController> logger) : base(serviceProvider, logger)
        {
            this.retrunOrderBLL = retrunOrderBLL;
        }

        [HttpGet("list")]
        public ReturnOrderListDto List(long shopSN, int status, DateTime create_start, DateTime create_end)
        {
            //定单列表 
            ReturnOrderListDto dto = new ReturnOrderListDto();
            try
            {
                List<ReturnOrderContentDto> orderList = this.retrunOrderBLL.Query(shopSN, status, create_start, create_end);
                foreach (ReturnOrderContentDto orderEntity in orderList)
                {
                    List<ReturnOrderDetailEntity> detial = this.retrunOrderBLL.QueryDetail(orderEntity.SN);
                    orderEntity.detail = detial;
                }
                dto.data = orderList;
            }
            catch (Exception ex)
            {
                dto = new ReturnOrderListDto();
                dto.error = new Error() { code = -1, msg = ex.Message };
                base.WriteException("List", ex);
            }
            return dto;
        }


    }
}
